package de.koller.magnitude;

import de.koller.aframe.gl.IARoot;
import de.koller.aframe.util.ALoop;
import de.koller.aframe.util.misc.ATimer;
import de.koller.aframe.util.node.NodeA;
import de.koller.aframe.util.thread.ICommand;
import de.koller.magnitude.entity.MDataRoot;
import de.koller.magnitude.entity.MEngineRoot;
import de.koller.magnitude.web.WebDisplayRoot;
import de.koller.oceanFramework.tree.Child;
import java.util.Random;

public class MRoot extends NodeA implements IARoot {
	public static final Random RND = new Random();
	
	private final ALoop loop = new ALoop( this );
	
	private ATimer roundTimer = new ATimer( 1000 );
			
	@Child public final WebDisplayRoot web = new WebDisplayRoot();
	@Child public final MDataRoot data = new MDataRoot();
	@Child public final MEngineRoot engine = new MEngineRoot();
	
	@Override
	protected void init() {
		super.init();
		
		this.setIgnoreChildRender( true );
	}

	@Override
	protected void update( int elapsedTime ) {
		super.update( elapsedTime );
		
		if( roundTimer.step( elapsedTime ) )
			this.secondaryUpdate();
	}
	
	@Override
	protected void release() {
		super.release();
		
	}

	public void start() {
		loop.begin();
	}
	
	public void stop() {
		loop.stop();
	}

	public void call( ICommand command ) {
		loop.thread.call( command );
	}

	@Override
	public long getSystemTime() {
		return System.currentTimeMillis();
	}

}
